using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.ComponentModel;

namespace Library.WebControls
{
	[Serializable(), DefaultProperty("Text"), ToolboxData("<{0}:ContentPaneFooter runat=server></{0}:ContentPaneFooter>"),
	System.ComponentModel.Designer("System.Web.UI.Design.WebControls.TableDesigner, System.Design, Version=1.0.5000.0, Culture=neutral, publicKeyToken=b03f5f7f11d50a3a")]
	public class ContentPaneFooter: System.Web.UI.WebControls.Table, IPostBackDataHandler
	{

		[EditorBrowsable(EditorBrowsableState.Always), Browsable(true)]
		public event EventHandler Confirmed;
		public event EventHandler NavigateBack;
		private Button btnConfirm;
		private Button btnNavigateBack;

		[Bindable(true), Category("Behavior"), DefaultValue(true)]
		public bool CausesValidation
		{
			get
			{
				if (this.ViewState["__causesValidation"] == null )
					return true;
				else
					return (bool)this.ViewState["__causesValidation"];
			}
			set
			{
				this.ViewState["__causesValidation"] = value;
			}
		}


		[Bindable(true), Category("Appearance"), DefaultValue(true)]
		public bool NavigateBackVisible
		{
			get
			{
				if (this.ViewState["__navigateBackVisible"] == null)
					return true;
				else
					return (bool)this.ViewState["__navigateBackVisible"];

			}
			set
			{
				this.ViewState["__navigateBackVisible"] = value;
			}
		}


		[Bindable(true), Category("Appearance"), DefaultValue("")]
		public string ButtonsCssclass
		{
			get
			{
				if ( this.ViewState["__buttonsCssclass"] == null )
					return "";
				else
					return (string)this.ViewState["__buttonsCssclass"];

			}
			set
			{
				this.ViewState["__buttonsCssclass"] = value;
			}
		}


		[Bindable(true), Category("Appearance"), DefaultValue("Back")]
		public string NavigateBackText
		{
			get
			{
				return (this.ViewState["__navigateBackText"] == null ? "Back" : (string)this.ViewState["__navigateBackText"]);
			}
			set
			{
				this.ViewState["__navigateBackText"] = value;
			}
		}


		[Bindable(true), Category("Appearance"), DefaultValue("")]
		public string NavigateBackClientFunction
		{
			get
			{
				if ( this.ViewState["__navigateBackClientFunction"] == null )
					return "";
				else
					return (string)this.ViewState["__navigateBackClientFunction"];
			}
			set
			{
				this.ViewState["__navigateBackClientFunction"] = value;
			}
		}


		[Bindable(true), Category("Appearance"), DefaultValue("OK")]
		public string ConfirmText
		{
			get
			{
				return ( this.ViewState["__confirmText"] == null ? "OK" : (string)this.ViewState["__confirmText"]);
			}
			set
			{
				this.ViewState["__confirmText"] = value;
			}
		}


		[Bindable(true), Category("Appearance"), DefaultValue("")]
		public string ConfirmClientFunction
		{
			get
			{
				if ( this.ViewState["__confirmClientFunction"] == null )
					return "";
				else
					return (string)this.ViewState["__confirmClientFunction"];
			}
			set
			{
				this.ViewState["__confirmClientFunction"] = value;
			}
		}


		public Button ConfirmButton
		{
			get
			{
				if ( btnConfirm == null )
				{
					btnConfirm = new Button();
					btnConfirm.ID = "btnConfirm";
					btnConfirm.Text = this.ConfirmText;
					btnConfirm.Attributes["class"] = this.ButtonsCssclass;
					btnConfirm.CausesValidation = this.CausesValidation;
					//btnConfirm.Attributes["onclick"] = this.Page.GetPostBackeventReference(btnConfirm, "");
				}
				return btnConfirm;
			}
			set
			{
				btnConfirm = value;
			}
		}

		private Button NavigateBackButton
		{
			get
			{
				if ( btnNavigateBack == null )
				{
					btnNavigateBack = new Button();
					btnNavigateBack.ID = "btnNavigateBack";
					btnNavigateBack.Text = this.NavigateBackText;
					btnNavigateBack.Attributes["class"] = this.ButtonsCssclass;
					btnNavigateBack.CausesValidation = false;
				}
				return btnNavigateBack;
			}
			set
			{
				btnNavigateBack = value;
			}
		}


		protected override void OnInit(EventArgs e)
		{
			if ( this.ViewState["__navigateBackClientFunction"] == null )
				this.ViewState["__navigateBackClientFunction"] = "javascript:history.back()";

			base.OnInit(e);
		}


		protected override void OnPreRender(EventArgs e)
		{
			this.Page.RegisterRequiresPostBack(this);
			base.OnPreRender(e);
		}


		protected override void Render(HtmlTextWriter output)
		{
			this.Rows.Add(new TableRow());
			this.Rows[0].Cells.AddRange(new TableCell[] {new TableCell(), new TableCell()});
			this.Rows[0].Cells[0].Controls.Add((this.NavigateBackVisible ? (Control)this.NavigateBackButton : (Control)new LiteralControl("&nbsp")));
			this.Rows[0].Cells[1].Controls.Add(this.ConfirmButton);
			this.Rows[0].Cells[1].HorizontalAlign = HorizontalAlign.Right;
			if ( this.Confirmed == null )
				this.ConfirmButton.Attributes["onclick"] = this.ConfirmClientFunction + ";return false;";

			if ( this.NavigateBack == null )
			{
				this.NavigateBackButton.Attributes["type"] = "button";
				this.NavigateBackButton.Attributes["onclick"] = this.NavigateBackClientFunction + ";return false;";
			}
			base.Render(output);
		}


		bool System.Web.UI.IPostBackDataHandler.LoadPostData(string postDataKey, System.Collections.Specialized.NameValueCollection postCollection)
		{
			if ( postDataKey == this.ClientID )
			{
				if ( ! (postCollection[this.ConfirmButton.ClientID] == null & this.Events["Confirmed"] == null) )
				{
					this.Confirmed(this, new EventArgs());
				}
			}
			else if  (!(postCollection[this.NavigateBackButton.ClientID] == null & this.Events["NavigateBack"] == null) )
				this.NavigateBack(this, new EventArgs());
			//string postedValue = postCollection[postDataKey];
			return false;
		}

		
		void System.Web.UI.IPostBackDataHandler.RaisePostDataChangedEvent()
		{
		}
	}
}
